// Fill out your copyright notice in the Description page of Project Settings.


#include "STreeItem_Folder.h"
#include "SlateOptMacros.h"
#include "Widgets/Layout/SScaleBox.h"

BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION

void STreeItem_Folder::Construct(const FArguments& InArgs)
{
	SAssignNew(pItemText, STextBlock)
	.Text(FText::FromString(InArgs._itemText))
	.Justification(ETextJustify::Type::Center)
	.ColorAndOpacity(mTextColor_Default);
	
	SetWidthOverride(InArgs._widthOverride);
	SetHeightOverride(InArgs._heightOverride);
	
	ChildSlot
	.HAlign(HAlign_Fill)
	.VAlign(VAlign_Fill)
	.Padding(0.f)
	[
		SNew(SBorder)
		.HAlign(HAlign_Fill)
		.VAlign(VAlign_Fill)
		.Padding(0.f)
		.BorderImage(new FSlateColorBrush{FLinearColor{0.f, 0.06301f, 0.127438f, 1.f}})
		[
			SNew(SVerticalBox)
			// Top Border
			+SVerticalBox::Slot()
			.FillHeight(0.1f * InArgs._fillRatioTopBottom)
			.HAlign(HAlign_Fill)
			.VAlign(VAlign_Fill)
			.Padding(0.f)
			[
				SNew(SBorder)
				.HAlign(HAlign_Fill)
				.VAlign(VAlign_Fill)
				.BorderImage(new FSlateColorBrush{FLinearColor{0.007499f, 0.007499f, 0.007499f, 1.f}})
			]
			
			// Horizontal Box
			+SVerticalBox::Slot()
			.FillHeight(1.f)
			.HAlign(HAlign_Fill)
			.VAlign(VAlign_Fill)
			[
				SNew(SHorizontalBox)
				// Left Border
				+SHorizontalBox::Slot()
				.FillWidth(0.02f * InArgs._fillRatioLeftRight)
				.HAlign(HAlign_Fill)
				.VAlign(VAlign_Fill)
				.Padding(0.f)
				[
					SNew(SBorder)
					.BorderImage(new FSlateColorBrush{FLinearColor{0.007499f, 0.007499f, 0.007499f, 1.f}})
				]
				
				// Scale Box
				+SHorizontalBox::Slot()
				.FillWidth(1.f)
				.HAlign(HAlign_Fill)
				.VAlign(VAlign_Fill)
				.Padding(0.f)
				[
					SNew(SScaleBox)
					.HAlign(HAlign_Fill)
					.VAlign(VAlign_Fill)
					.Stretch(EStretch::ScaleToFit)
					[
						pItemText.ToSharedRef()
					]
				]
				
				// Right Border
				+SHorizontalBox::Slot()
				.FillWidth(0.02f * InArgs._fillRatioLeftRight)
				.HAlign(HAlign_Fill)
				.VAlign(VAlign_Fill)
				.Padding(0.f)
				[
					SNew(SBorder)
					.BorderImage(new FSlateColorBrush{FLinearColor{0.007499f, 0.007499f, 0.007499f, 1.f}})
				]
			]
			
			// Bottom Border
			+SVerticalBox::Slot()
			.FillHeight(0.1f * InArgs._fillRatioTopBottom)
			.HAlign(HAlign_Fill)
			.VAlign(VAlign_Fill)
			.Padding(0.f)
			[
				SNew(SBorder)
				.HAlign(HAlign_Fill)
				.VAlign(VAlign_Fill)
				.BorderImage(new FSlateColorBrush{FLinearColor{0.007499f, 0.007499f, 0.007499f, 1.f}})
			]
		]
	];
	
}

void STreeItem_Folder::OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
	SBox::OnMouseEnter(MyGeometry, MouseEvent);

	if (pItemText.IsValid())
		pItemText->SetColorAndOpacity(mTextColor_Hover);
}

void STreeItem_Folder::OnMouseLeave(const FPointerEvent& MouseEvent)
{
	SBox::OnMouseLeave(MouseEvent);

	if (pItemText.IsValid())
		pItemText->SetColorAndOpacity(mTextColor_Default);
}

END_SLATE_FUNCTION_BUILD_OPTIMIZATION
